define(['core/exception'], function (Exception) {
    "use strict";

    function Geolocation() {
        this.watchId;        
    };

    Geolocation.prototype = {
        constructor: Geolocation,
        dispose: function () {
            this.stopWatchPosition();
        },
        getCurrentPosition: function (success, error) {
            console.log('model/geolocation.js. navigator.geolocation.getCurrentPosition.');
            if (navigator.geolocation == undefined) throw new Exception("geolocation is not supported.");
            navigator.geolocation.getCurrentPosition(success, error, { enableHighAccuracy: true });
        },
        watchPosition: function (success, error) {
            if (this.watchId) {
                console.log('model/geolocation.js. navigator.geolocation.watchPosition');
                this.watchId = navigator.geolocation.watchPosition(success, error, { enableHighAccuracy: true });
            }
        },
        stopWatchPosition: function () {
            if (this.watchId) {
                console.log('model/geolocation.js. navigator.geolocation.clearWatch');
                navigator.geolocation.clearWatch(this.watchId);
            }
        }
    };

    console.log('model/geolocation.js');
    return new Geolocation();
});